package com.dlc.felear.xiaoensale.customView;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dlc.felear.xiaoensale.R;


public class ShowMsgDialog extends Dialog implements View.OnClickListener {
    private Button btnC;
    private ImageView ivQr;
    private TextView tvTitle, tvMsg;
    private Context context;

    public ShowMsgDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public ShowMsgDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    private void initView(Context context) {
        this.context = context;
        View root = LayoutInflater.from(context).inflate(R.layout.show_msg_dialog, null);
        setContentView(root);
        setCanceledOnTouchOutside(false);
        btnC = findViewById(R.id.btn_d_confirm);
        btnC.setOnClickListener(this);
        ivQr = findViewById(R.id.iv_d_qr);
        tvTitle = findViewById(R.id.tv_d_title);
        tvMsg = findViewById(R.id.tv_d_msg);
    }

    /**
     * 设置提示内容
     *
     * @param info
     */
    public void setMsg(String info) {
        if (tvMsg != null) {
            tvMsg.setText(info);
        }
    }

    /**
     * 显示二维码
     *
     * @param url
     */
    public void setQr(String url) {
        Glide.with(context).load(url).into(ivQr);
    }

    /**
     * 设置title
     *
     * @param title
     */
    public void setTtitle(String title) {
        if (tvTitle != null) {
            tvTitle.setText(title);
        }
    }


    public void showDialog() {
        show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_d_confirm:
                dismiss();
                break;
            default:
        }
    }

}
